package com.wisemoresystem.seal.action.useapply.search;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wisemoresystem.seal.base.action.ProjBaseAction;
import com.wisemoresystem.seal.base.tip.Tip;
import com.wisemoresystem.seal.model.t_mac;
import com.wisemoresystem.seal.model.t_seal;
import com.wisemoresystem.seal.model.t_seal_use_apply;
import com.wisemoresystem.seal.model.t_use_search_log;
import com.wisemoresystem.seal.model.t_user;
import com.wisemoresystem.seal.service.UseSealSearchService;
import com.wisemoresystem.seal.util.DateTools;
import com.wisemoresystem.seal.web.WebTools;

/**
 * 用印自查 和 自查历史
 * 
 * @author Administrator
 *
 */
@Controller("ixUseSelfSearch")
@Scope("prototype")
@RequestMapping("/ix/useapply/search")
public class UseSelfSearchAction extends ProjBaseAction {

	@Autowired
	private UseSealSearchService uService;

	//需要用印自查的列表
	@RequestMapping("/list")
	public ModelAndView list(String srh_reason, String srh_name) {

		List<Map<String, Object>> list = uService.selectUseSealLogList(
				srh_reason, srh_name, page);

		ModelAndView mv = new ModelAndView("/jsp/useapply/search/list");
		mv.addObject("list", list);
		return mv;
	}
	
	//用印的详细情况
	@RequestMapping("/detail")
	public ModelAndView detail(String apply_id) {

		t_seal_use_apply apply = oc.findObjById(apply_id,
				t_seal_use_apply.class);
		t_user user = oc.findObjById(apply.getApply_user(), t_user.class);
		t_seal seal = oc.findObjById(apply.getSeal_id(), t_seal.class);
		t_mac mac = oc.findObjById(apply.getMac_id(), t_mac.class);
		List<Map<String, Object>> list = uService.selectUseApplyPpList(apply_id);
		
		ModelAndView mv = new ModelAndView("/jsp/useapply/search/detail");
		mv.addObject("apply", apply);
		mv.addObject("user", user);
		mv.addObject("seal", seal);
		mv.addObject("mac", mac);
		mv.addObject("list", list);
		return mv;
	}
	
	//用印自查
	@RequestMapping("/add")
	public ModelAndView detail(t_use_search_log log,String apply_id) {

		log.setBank_id(WebTools.getCurrentBankId());
		log.setUser_id(WebTools.getCurrentUserId());
		log.setSearch_time(DateTools.getTimestampTodayStr());
		log.setSearch_type("self search");
		oc.saveObj(log);
		
		t_seal_use_apply apply = oc.findObjById(apply_id,
				t_seal_use_apply.class);
		apply.setVerify_status("已自审 ");
		oc.updateObj(apply);
		
		super.setTipMsg("操作成功！", Tip.Type.success);
		ModelAndView mv = new ModelAndView("redirect:list.htm");
		return mv;
	}

	@RequestMapping("/search_list")
	public ModelAndView search_list(String srh_content, String srh_user,
			String srh_start, String srh_end) {

		List<Map<String, Object>> list = uService.selectSearchLogList(
				srh_content, srh_start, srh_end, srh_user, page);

		ModelAndView mv = new ModelAndView("/jsp/useapply/search/search_list");
		mv.addObject("list", list);
		return mv;
	}

}
